/** ***********************************************
 * CodeGen
 *
 * @author  Jonnie Spratley
 * @date 3/05/2009
 * @licence MCIYC
 * @website http://jonniespratley.com/code
 * @contact jonniespratley@gmail.com
 *********************************************** */
package com.jonniespratley.codegen.vo
{
	import mx.collections.ArrayCollection;


	[Bindable]
	public class PHPClassVO
	{

		public var className:String;
		public var classFilename:String;
		public var classLocation:String;
		public var classComments:String;
		public var classMethods:ArrayCollection;

		public function  PHPClassVO( obj:Object = null )
		{
			if ( obj != null )
			{
				this.className = obj['className'];
				this.classFilename = obj['classFilename'];
				this.classComments = cleanComments( obj['classComments'] );
				this.classLocation = obj['classLocation'];

				if ( obj['classMethods'] )
				{
					//set the fields comming back as an Array
					var tempArray:Array = obj['classMethods'] as Array;

					//create a temp arraycollection so return to the aFields
					var tempAc:ArrayCollection = new ArrayCollection();

					//loop through every string in the fields array
					for ( var s:String in tempArray )
					{
						//for each object add it to the temp collection
						tempAc.addItem( new PHPMethodVO( tempArray[ s ] ) );
					}
					//set the array collection to the build one of value objects
					this.classMethods = tempAc;
				}
			}
		}

		public function get children():Array
		{
			return this.classMethods.toArray();
		}

		public function get label():String
		{
			return this.className;
		}

		private function cleanComments( str:String ):String
		{
			//@param
			var pattern:RegExp = /(@+\w*)/gim;
			var newString:String = '';
			var matched:Array = str.match( pattern );
			
			for( var i:int = 0; i < matched.length; i++ )
			{
				str.replace( matched[ i ], '\n' + matched[ i ] );
				trace( matched[ i ] );
			}
			newString = str;
			trace( str );
			trace( newString );
			return newString;
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	}
}